#!/bin/bash

set -e

if [[ -n "${RASTER_VISION_DEBUG}" ]]; then
    set -x
fi

function usage() {
    echo -n \
         "Usage: $(basename "$0")
Setup AWS Batch with a compute environment, job queue and job definition. This
should only be done once per AWS account.
"
}

PROJECT_ROOT="$(dirname "$(dirname "$(readlink -f "${0}")")")"
BATCH_CONFIG=$PROJECT_ROOT/deployment/batch

aws batch create-compute-environment --cli-input-json file://$BATCH_CONFIG/compute_environment_gpu.json
aws batch create-compute-environment --cli-input-json file://$BATCH_CONFIG/compute_environment_cpu.json
echo 'Waiting 10s...'
sleep 10s

aws batch create-job-queue --cli-input-json file://$BATCH_CONFIG/job_queue_gpu.json
aws batch create-job-queue --cli-input-json file://$BATCH_CONFIG/job_queue_cpu.json
echo 'Waiting 10s...'
sleep 10s

aws batch register-job-definition --cli-input-json file://$BATCH_CONFIG/job_def_gpu.json
aws batch register-job-definition --cli-input-json file://$BATCH_CONFIG/job_def_cpu.json
